import * as React from "react"
import type { Metadata } from "next"
import { unstable_noStore as noStore } from "next/cache"
import { getServerSession } from "next-auth"
import { Shell } from "@/components/shell"
import { NoticeClient } from "@/components/notice/notice-client"
import { InformationButton } from "@/components/information/information-button"
import { getNoticeLists } from "@/lib/notice/service"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { useTranslation } from "@/i18n"

export const metadata: Metadata = {
  title: "공지사항 관리",
  description: "페이지별 공지사항을 관리합니다.",
}

interface noticePageProps {
  params: Promise<{ lng: string }>
}

export default async function NoticePage({ params }: noticePageProps) {
  const { lng } = await params
  const { t } = await useTranslation(lng, 'menu')

  noStore()

  // 세션에서 사용자 ID 가져오기
  const session = await getServerSession(authOptions)
  const currentUserId = session?.user?.id ? parseInt(session.user.id) : undefined


  // 간단한 초기 데이터 로딩
  const initialData = await getNoticeLists({
    page: 1,
    perPage: 50,
    search: "",
    sort: [{ id: "createdAt", desc: true }],
    flags: [],
    filters: [],
    joinOperator: "and",
    pagePath: "",
    title: "",
    content: "",
    authorId: currentUserId || null,
    isActive: true,
    from: "",
    to: "",
  })
  

  return (
    <Shell className="gap-2">
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                {t('menu.information_system.notice')}
              </h2>
              <InformationButton pagePath="evcp/notice" />
            </div>
          </div>
        </div>
      </div>
      <NoticeClient initialData={initialData?.data || []} currentUserId={currentUserId} />
    </Shell>
  )
} 
